
//
//  ServiceDetailsView.m
//  afn
//
//  Created by mac on 2018/5/9.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "ServiceDetailsView.h"
#import "ServiceDetailsTableViewCell.h"
#import "PlaceOrderViewController.h"

@implementation ServiceDetailsView

-(void)creatView{
    _tableView=[BaseTableView new];
    [self addSubview:_tableView];
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_offset(0);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(-50);
    }];
    _tableView.backgroundColor=_LightGrey;
    _tableView.delegate=self;
    _tableView.dataSource=self;
    
    UIView *bottomView=[UIView new];
    [self addSubview:bottomView];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(50);
    }];
    bottomView.backgroundColor=[UIColor whiteColor];
    
    UIView *xianView=[UIView new];
    [bottomView addSubview:xianView];
    [xianView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        make.height.mas_equalTo(1);
    }];
    xianView.backgroundColor=_LightGrey;
    
    UIButton *fenXiangBtn=[UIButton new];
    [bottomView addSubview:fenXiangBtn];
    [fenXiangBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.mas_equalTo(0);
        make.width.mas_equalTo(_mainW/2);
        make.top.mas_equalTo(xianView.mas_bottom);
    }];
    [fenXiangBtn setImage:[UIImage imageNamed:@"ico-fenxiang"] forState:0];
    [fenXiangBtn setTitle:@"\t\t分享" forState:0];
    [fenXiangBtn setTitleColor:ColorWithRGB(149, 149, 149) forState:0];
    fenXiangBtn.titleLabel.font=[UIFont systemFontOfSize:16];
    
    UIButton *btn=[UIButton new];
    [bottomView addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.bottom.mas_equalTo(0);
        make.width.mas_equalTo(_mainW/2);
    }];
    btn.backgroundColor=_backgroundColor;
    [btn setTitle:@"立即抢购" forState:0];
    [btn setTitleColor:[UIColor whiteColor]forState:0];
    btn.titleLabel.font=[UIFont systemFontOfSize:16];
    [btn addTarget:self action:@selector(qiangGou) forControlEvents:UIControlEventTouchUpInside];
}

-(void)qiangGou{
    PlaceOrderViewController *placeOrder=[[PlaceOrderViewController alloc] init];
    placeOrder.model=_model;
    [gongju pushNextViewController:self.viewController andRootController:placeOrder];
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ServiceDetailsTableViewCell *cell=[[ServiceDetailsTableViewCell alloc] init];
    cell.model=_model;
    if (indexPath.row==0) {
       [cell creatView1];
    }
//    if (indexPath.row==1) {
//        [cell creawtView2];
//    }
    if (indexPath.row==2) {
         [cell creatView3];
    }if (indexPath.row==3) {
        [cell setFrame:CGRectMake(0, 0, _mainW, [cell creatView4])];
    }if (indexPath.row==4) {
        [cell setFrame:CGRectMake(0, 0, _mainW, [cell creatView5])];
    }

    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}



-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==0) {
        return 150;
    }if (indexPath.row==2) {
        return 77;
    }if (indexPath.row==3||indexPath.row==4) {
        UITableViewCell *cell;
        cell= [self tableView:tableView cellForRowAtIndexPath:indexPath];
        return cell.frame.size.height;
    }
    return 0;
}

@end
